package com.miyake.loveviewweb.shared.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.google.appengine.api.datastore.Key;
import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;

@Model(schemaVersion = 1)
public class DataModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;

    /**
     * Returns the key.
     *
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * Sets the key.
     *
     * @param key
     *            the key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * Returns the version.
     *
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version.
     *
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        DataModel other = (DataModel) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        return true;
    }
    
    /**
     * @return the folder
     */
    public Key getFolder() {
        return folder;
    }

    /**
     * @param folder the folder to set
     */
    public void setFolder(Key folder) {
        this.folder = folder;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the dataType
     */
    public DataType getDataType() {
        return dataType;
    }

    /**
     * @param dataType the dataType to set
     */
    public void setDataType(DataType dataType) {
        this.dataType = dataType;
    }

    /**
     * @return the sourceType
     */
    public SourceType getSourceType() {
        return sourceType;
    }

    /**
     * @param sourceType the sourceType to set
     */
    public void setSourceType(SourceType sourceType) {
        this.sourceType = sourceType;
    }

    /**
     * @return the sourceData
     */
    public Key getSourceData() {
        return sourceData;
    }

    /**
     * @param sourceData the sourceData to set
     */
    public void setSourceData(Key sourceData) {
        this.sourceData = sourceData;
    }

    /**
     * @return the originalData
     */
    public Key getOriginalData() {
        return originalData;
    }

    /**
     * @param originalData the originalData to set
     */
    public void setOriginalData(Key originalData) {
        this.originalData = originalData;
    }

    /**
     * @return the chartColumns
     */
    public int getChartColumns() {
        return chartColumns;
    }

    /**
     * @param chartColumns the chartColumns to set
     */
    public void setChartColumns(int chartColumns) {
        this.chartColumns = chartColumns;
    }

    /**
     * @return the chartListVisible
     */
    public boolean isChartListVisible() {
        return chartListVisible;
    }

    /**
     * @param chartListVisible the chartListVisible to set
     */
    public void setChartListVisible(boolean chartListVisible) {
        this.chartListVisible = chartListVisible;
    }

    /**
     * @return the owner
     */
    public Key getOwner() {
        return owner;
    }

    /**
     * @param owner the owner to set
     */
    public void setOwner(Key owner) {
        this.owner = owner;
    }

    /**
     * @return the dataBody
     */
    public Key getDataBody() {
        return dataBody;
    }

    /**
     * @param dataBody the dataBody to set
     */
    public void setDataBody(Key dataBody) {
        this.dataBody = dataBody;
    }

    /**
     * @return the valueKeys
     */
    public List<Key> getValueKeys() {
        return valueKeys;
    }

    /**
     * @param valueKeys the valueKeys to set
     */
    public void setValueKeys(List<Key> valueKeys) {
        this.valueKeys = valueKeys;
    }

    /**
     * @return the xyDataBody
     */
    public XyDataBodyModel getXyDataBody() {
        return xyDataBody;
    }

    /**
     * @param xyDataBody the xyDataBody to set
     */
    public void setXyDataBody(XyDataBodyModel xyDataBody) {
        this.xyDataBody = xyDataBody;
    }

    /**
     * @return the imageDataBody
     */
    public ImageDataBodyModel getImageDataBody() {
        return imageDataBody;
    }

    /**
     * @param imageDataBody the imageDataBody to set
     */
    public void setImageDataBody(ImageDataBodyModel imageDataBody) {
        this.imageDataBody = imageDataBody;
    }

    /**
     * @return the content
     */
    public boolean isContent() {
        return content;
    }

    /**
     * @param content the content to set
     */
    public void setContent(boolean content) {
        this.content = content;
    }

    /**
     * @return the parsed
     */
    public boolean isParsed() {
        return parsed;
    }

    /**
     * @param parsed the parsed to set
     */
    public void setParsed(boolean parsed) {
        this.parsed = parsed;
    }


    /**
     * @return the originalDataUrl
     */
    public String getOriginalDataUrl() {
        return originalDataUrl;
    }

    /**
     * @param originalDataUrl the originalDataUrl to set
     */
    public void setOriginalDataUrl(String originalDataUrl) {
        this.originalDataUrl = originalDataUrl;
    }


    /**
     * @return the values
     */
    public List<ValueModel> getValues() {
        return values;
    }

    /**
     * @param values the values to set
     */
    public void setValues(List<ValueModel> values) {
        this.values = values;
    }

    /**
     * @return the plugin
     */
    public Key getPlugin() {
        return plugin;
    }

    /**
     * @param plugin the plugin to set
     */
    public void setPlugin(Key plugin) {
        this.plugin = plugin;
    }

    private Key folder;
    
    private String name;
    
    public enum SourceType {
        Manual, // Manual input with web browser
        File,   // Uploaded File
        Plugin, // Created or analyzed with plugin
    };
    
    public enum DataType {
        ValueArray, 
        Image, 
        Audio
    }
    
    // Data Type
    private DataType dataType;
    
    // DataType : File
    private SourceType sourceType;
    
    // If this data is analyzed
    private Key sourceData; // If this data is analyzed, input data key should be set.
    private Key plugin;
    
    private Key originalData;
    
    // View Settings
    private int chartColumns = 1;
    private boolean chartListVisible;
    
    // Owner of this data
    private Key owner;
    
    // Data Body
    private Key dataBody;
    
    // Values
    private List<Key> valueKeys = new ArrayList<Key>();
    
    private boolean parsed;

    @Attribute(persistent=false)
    private XyDataBodyModel xyDataBody;
    
    @Attribute(persistent=false)
    private ImageDataBodyModel imageDataBody;
 
    @Attribute(persistent=false)
    private boolean content;
    
    @Attribute(persistent=false)
    private String originalDataUrl;  
    
    @Attribute(persistent=false)
    private List<ValueModel> values = new ArrayList<ValueModel>();
}
